package com.small.xx.ai.spring.toolcall.component.time.function;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.small.xx.ai.spring.toolcall.component.time.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Function;

public class TimeFunctionService implements Function<TimeFunctionService.Request, TimeFunctionService.Response> {
    private static final Logger logger = LoggerFactory.getLogger(TimeFunctionService.class);
    @Override
    public Response apply(Request request) {
        System.out.println("TimeFunctionService.apply");
        System.out.println("request = " + request);
        String timeZoneId = request.timeZoneId;
        logger.info("当前时间的时区 {}", timeZoneId);
        return new Response(String.format("The current time zone is %s and the current time is " + "%s", timeZoneId,
            TimeUtils.getTimeByZoneId(timeZoneId)));
    }

    @JsonInclude(JsonInclude.Include.NON_NULL)
    @JsonClassDescription("根据时区ID获取当前时间")
    public record Request(@JsonProperty(required = true, value = "timeZoneId") @JsonPropertyDescription(
        "时区ID, 例如：Asia/Shanghai") String timeZoneId) {
    }

    public record Response(String description) {
    }

}
